package com.cardvalue.sys.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.preference.DialogPreference;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.cardvalue.sys.R;
import com.cardvalue.sys.base.BaseActivity;
import com.cardvalue.sys.dialog.IosDailog;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 个人信息
 */
public class ShowUserInfo extends BaseActivity {
    @Bind(R.id.userinfo_list)  ListView  mListView;
    @Bind(R.id.button1) Button  mButton;//退出的按钮
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_user_info);
        ButterKnife.bind(this);
        setHeaderFields(0, R.string.user,0,R.mipmap.back, 0,0);
        getData();
    }

    /**
     * ListView 里面的数据
     */
    public void getData(){
        List<Map<String,Object>> data=new ArrayList<>();
        Map<String,Object> map=new HashMap<>();
        map.put("text1","");
        map.put("text2","姓名：");
        map.put("image2", "");
        data.add(map);

        map=new HashMap<>();
        map.put("text1","");
        map.put("text2","手机号：");
        map.put("image2", "");
        data.add(map);


        map=new HashMap<>();
        map.put("text1","");
        map.put("text2","身份证：");
        map.put("image2", "");
        data.add(map);

        map=new HashMap<>();
        map.put("text1","");
        map.put("text2","修改密码：");
        map.put("imag",R.mipmap.ic_right);
        data.add(map);


        SimpleAdapter adapter=new SimpleAdapter(this,data,R.layout.myaccount_list_2_layout,
                new String[]{"text1","text2","imag"},new int[]{R.id.text2,R.id.text1,R.id.imager_1});
        mListView.setDivider(null);
        mListView.setAdapter(adapter);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TextView tv = (TextView)view.findViewById(R.id.text1);
                if(tv.getText().toString().equals("修改密码：")){
                    Intent intent = new Intent(ShowUserInfo.this,ChangePwdActivity.class);
                    startActivity(intent);
                    ShowUserInfo.this.finish();
                }
            }
        });
    }

    @OnClick(R.id.button1) void clickBtn() {
        IosDailog.CustomAlert("退出", "退出后您将不能查看相关信息，确定要退出当前账号吗？",
                ShowUserInfo.this, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent =new Intent(ShowUserInfo.this,HomeActivity.class);
                        intent.putExtra("tagchang","0");
                        startActivity(intent);
                        dialog.cancel();
                        ShowUserInfo.this.finish();
                    }
                }, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
    }
}
